package cn.hchaojie.web.day04;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginServlet extends HttpServlet {
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		
		// 登陆成功，需要把用户信息放到session里面去
		String userName = req.getParameter("name");
		
		System.out.println(userName);
		
		// 把用户名放入session
		HttpSession session = req.getSession();
		session.setAttribute("user", userName);
		
		// 跳到user.jsp
		req.getRequestDispatcher("user.jsp").forward(req, resp);
	}
}
